/*
* @Author: Administrator
* @Date:   2017-11-03 15:38:09
* @Last Modified by:   Administrator
* @Last Modified time: 2017-11-22 10:54:48
*/
 
 $(function(){

    $("footer").load("layout/footer.html");
    $("header").load("layout/header2.html");

 var navHtml=$('#nav').html();
 var fankuilistHtml=$('#fankuilist').html();
 
 var goodsHtml=$('#goods').html();
 var kefuHtml=$('#kefu').html();
 var chenggongHtml=$('#chenggong').html();
// 
    $(function() {
              $.ajax({
                       type:"get",
                       url:"data/yztfuwu.json",
                       async:true,
                       success: function(data){
                        console.log(data);
                        var nav=data.nav;
                        var fankui=data.fankui;
                        // 推荐
                        $('.box-left').html(doT.template(navHtml)(nav));
                        $('.fankui-list').html(doT.template(fankuilistHtml)(fankui));
                        // $('.ad3').html(doT.template(ad3Html)(ad3));
                        // $('.zhuce').html(doT.template(zhuceHtml)(zhuce));
                       },
                       error: function(XMLHTTPRequest, textStatus, errorThrown){
                         console.log("XMLHttpRequest :"+ XMLHTTPRequest);
                         console.log("textStatus :"+textStatus);
                         console.log("errorThrown :"+errorThrown);
                       }
                     });
                
    });
    // goods
    $.ajax({
             type:"get",
             url:"data/goods.json",
             async:true,
             success: function(data){
              console.log(data);
              var goods=data.goods;
              window.price=data.goods[0].goods_price
              $('.goods-content').html(doT.template(goodsHtml)(goods));
             },
             error: function(XMLHTTPRequest, textStatus, errorThrown){
               console.log("XMLHttpRequest :"+ XMLHTTPRequest);
               console.log("textStatus :"+textStatus);
               console.log("errorThrown :"+errorThrown);
             }
           });
                
   // 客服
 $(function() {
              $.ajax({
                       type:"get",
                       url:"data/kefu.json",
                       async:true,
                       success: function(data){
                        console.log(data);
                        var kefu=data.kefu;

                        $('.linkpeople').html(doT.template(kefuHtml)(kefu));

                        var anli=data.kefu.slice(0,4)
                        $('.anli-list').html(doT.template(chenggongHtml)(anli));
                       },
                       error: function(XMLHTTPRequest, textStatus, errorThrown){
                         console.log("XMLHttpRequest :"+ XMLHTTPRequest);
                         console.log("textStatus :"+textStatus);
                         console.log("errorThrown :"+errorThrown);
                       }
                     });
                
    });

 // 导航栏
$(document).on("click",".navlis",function(){

  $(this).find("ul").show(400)
  $(this).siblings().find("ul").hide(400)
  if($(this).hasClass("show")){
    $(this).find("ul").hide(400)
    $(this).find(".sanjiaoicon").removeClass("xuanzhuan")
    $(this).removeClass("show")
  }else{
    $(this).find("ul").show(400)
    $(this).find(".sanjiaoicon").addClass("xuanzhuan")
    $(this).addClass("show")
  }
})
// 数量增减
var num=1;
console.log(window.price)  
$(document).on("click",".sy_plus",function() {
     num++;
    $(".sy_num").val(num);
    console.log(window.price)
    $(".price i").html(num*window.price)
});

// 减去
$(document).on("click",".sy_minus",function() {
    num--
    num = num < 1 ? 1 : num;
    $(".sy_num").val(num);
   $(".price i").html(num*window.price)
});

// 切换客服
var idx=0;
 $(document).on("click","span.down",function(){
    var length=$(".linkpeople li").length
    console.log(length)
    if (idx >= length-1) {
       idx==length-1;
    }else{
      idx++;
    }
   $("ul.linkpeople").css("left",-idx*140)
  })
 $(document).on("click","span.top",function(){
      if (idx <=0) {
         idx==0;
      }else{
        idx--;
      }
     $("ul.linkpeople").css("left",-idx*140)
  })

// var top =$(".jieshao").scrollTop();
//  $(window).scroll(function(event){
//   var top =$(".jieshao").scrollTop();
//      console.log(top)
//     });
//     
$(window).scroll(function(){  
        var scrollTop=document.body.scrollTop||document.documentElement.scrollTop;  
        console.log(scrollTop)
        if(scrollTop<=900){
          $(".fuwujianjie").addClass("bordertop")
          $(".kehufankui").removeClass("bordertop")
        }else{
           $(".fuwujianjie").removeClass("bordertop")
           $(".kehufankui").addClass("bordertop")
        }
    })  

})
